home *** CD-ROM | disk | FTP | other *** search
- /*
- * $RCSfile: setSocketOptions.c,v $
- * $Revision: 1.2 $
- * $Date: 1996/05/04 23:51:45 $
- */
- /**********************************************************************
- * EXODUS Database Toolkit Software
- * Copyright (c) 1991 Computer Sciences Department, University of
- * Wisconsin -- Madison
- * All Rights Reserved.
- *
- * Permission to use, copy, modify and distribute this software and its
- * documentation is hereby granted, provided that both the copyright
- * notice and this permission notice appear in all copies of the
- * software, derivative works or modified versions, and any portions
- * thereof, and that both notices appear in supporting documentation.
- *
- * THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY OF WISCONSIN --
- * MADISON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.
- * THE DEPARTMENT DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES
- * WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
- *
- * The EXODUS Project Group requests users of this software to return
- * any improvements or extensions that they make to:
- *
- * EXODUS Project Group
- * c/o David J. DeWitt and Michael J. Carey
- * Computer Sciences Department
- * University of Wisconsin -- Madison
- * Madison, WI 53706
- *
- * or exodus@cs.wisc.edu
- *
- * In addition, the EXODUS Project Group requests that users grant the
- * Computer Sciences Department rights to redistribute these changes.
- **********************************************************************/
- #include "sysdefs.h"
- #include <fcntl.h>
- #include <netinet/tcp.h>
- #include "ess.h"
- #include "checking.h"
- #include "trace.h"
- #include "error.h"
- #include "util_funcs.h"
-
- int
- setSocketOptions (
- int fd, /* socket id */
- int sendBufSize,
- int receiveBufSize
- )
-
- {
- struct protoent *protoInfo;
- int one = 1; /* for 4.3 BSD style setsockopt() */
- struct linger lingerInfo;
-
- TRACE(TR_MSG, TR_LEVEL_1);
-
- /*
- * set socket to not delay sending data
- */
- protoInfo = getprotobyname("tcp");
- if (protoInfo == NULL) {
- SM_ERROR(TYPE_SYS, errno);
- return(esmFAILURE);
- }
- if (setsockopt(fd, protoInfo->p_proto, TCP_NODELAY, (char*) &one, sizeof(one)) != 0) {
- SM_ERROR(TYPE_SYS, errno);
- return(esmFAILURE);
- }
-
- if (setsockopt(fd, SOL_SOCKET, SO_SNDBUF, (char *) &sendBufSize, sizeof(sendBufSize)) != 0) {
- SM_ERROR(TYPE_SYS, errno);
- return(esmFAILURE);
- }
- if (setsockopt(fd, SOL_SOCKET, SO_RCVBUF, (char *) &receiveBufSize, sizeof(receiveBufSize)) != 0) {
- SM_ERROR(TYPE_SYS, errno);
- return(esmFAILURE);
- }
-
- #ifdef COMMENT
- {
- int length;
- if (getsockopt(fd, SOL_SOCKET, SO_LINGER, (char *) &lingerInfo, &length) != 0) {
- SM_ERROR(TYPE_SYS, errno);
- return(esmFAILURE);
- }
- if (length != sizeof(lingerInfo)) {
- printf("getsockopt return linger size of %d instead of %d\n",
- length, sizeof(lingerInfo));
- }
- printf("Socket had linger_onoff:%d, l_linger:%d\n", lingerInfo.l_onoff, lingerInfo.l_linger);
- }
- #endif COMMENT;
-
- /*
- * Make sure the sockets don't wait to send any leftover date
- * once they have been closed
- */
- lingerInfo.l_onoff = 0;
- lingerInfo.l_linger = 0;
- if (setsockopt(fd, SOL_SOCKET, SO_LINGER, (char *) &lingerInfo, sizeof(lingerInfo)) != 0) {
- SM_ERROR(TYPE_SYS, errno);
- return(esmFAILURE);
- }
-
- return(esmNOERROR);
- }
-